﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core;
namespace WPFExcelReport
{
    class YCAFSSTAMMReport : BaseReport
    {
        #region ----------------PROPERTIES----------------------------------
        public OracleConnection OracleDB;
        public OracleCommand orlReadCommand = new OracleCommand();
        public IntexReptServBLClient proxy;
        private Dictionary<string, object> dicParamater;
        public DataSet dsResult;
        public DataSet setUI = new DataSet();
        string ABPAUFFKRS;
        string ABPAUFFLFD;
        string ABPAUFFPOS;
        string DocType;
        string CellName = "";
        string CellValue = "";
        string strCompany;
        string strExcelFile;
        #endregion
        public YCAFSSTAMMReport()
            : base()
        {
        }
        public YCAFSSTAMMReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            DocType = dicParamater["DocType"].ToString().Trim();
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            #region Excel  columns
            /*columns.Add("VAAART");
            columns.Add("DES");
            columns.Add("TOTWIDTH");
            columns.Add("VALWIDTH");
            columns.Add("WAFGRQM");
            columns.Add("WAFGRLFD");
            columns.Add("YARN");
            columns.Add("WABIND");
            columns.Add("WALOHNA");
            columns.Add("SUPP");
            columns.Add("COMP");
            columns.Add("WANEUD");
            columns.Add("REMARK");*/
            #endregion           						

        }
        #region------------------------------Function------------------------

        private void FillInARTICLE(DataTable dtSource)
        {
            try
            {
                Queue CellQueue = new Queue();
                CellQueue.Clear();
                string DATE="";
                foreach (DataRow dwSource in dtSource.Rows)
                {
                    CellName = "VAAART";
                    CellValue = dwSource["VAAART"].ToString();
                    exAgent.SetCellValue(2,5,CellValue);
                    CellName = "VAAKURZBEZ";
                    CellValue = dwSource["VAAKURZBEZ"].ToString().Trim();
                    exAgent.SetCellValue(3, 5, CellValue);
                    CellName = "VAABEZ";
                    CellValue = dwSource["VAABEZ"].ToString();
                    exAgent.SetCellValue(4, 3, CellValue);
                    CellName = "COMP";
                    CellValue = dwSource["COMP"].ToString().Trim();
                    exAgent.SetCellValue(7, 1, CellValue);
                    CellName = "WIDTH";
                    CellValue = dwSource["WIDTH"].ToString();
                    exAgent.SetCellValue(10, 4, CellValue);
                    CellName = "WEIGHT";
                    CellValue = dwSource["WEIGHT"].ToString();
                    exAgent.SetCellValue(11, 4, CellValue);
                    DATE = DateTime.Now.Year.ToString() +"-"+ DateTime.Now.Month.ToString() +"-"+ DateTime.Now.Day.ToString();
                    exAgent.SetCellValue(12, 4, DATE);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["WASTAMM"];                
                DataTable dtOutput = new DataTable();
                dtOutput.Columns.Add("VAAART", typeof(System.String));
                dtOutput.Columns.Add("DES", typeof(System.String));
                dtOutput.Columns.Add("TOTWIDTH", typeof(System.String));
                dtOutput.Columns.Add("VALWIDTH", typeof(System.String));
                dtOutput.Columns.Add("WAFGRQM", typeof(System.String));
                dtOutput.Columns.Add("WAFGRLFD", typeof(System.String));
                dtOutput.Columns.Add("YARN", typeof(System.String));
                dtOutput.Columns.Add("WABIND", typeof(System.String));
                dtOutput.Columns.Add("WALOHNA", typeof(System.String));
                dtOutput.Columns.Add("SUPP", typeof(System.String));
                dtOutput.Columns.Add("COMP", typeof(System.String));
                dtOutput.Columns.Add("WANEUD", typeof(System.String));
                dtOutput.Columns.Add("REMARK", typeof(System.String));
                dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);

                exAgent.DataTableToExcel(dtOutput, 3, 1);
                
                /*int count = dtOutput.Rows.Count;
                exAgent.BatchConvert2Number(6, 7, count + 5, 27);
                exAgent.SetCellValue(1, 1, " ");*/

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public void GetReport(string fileType,string ART,string type,int copies=1,bool chooseprinter=false)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "LABEL";
            strExcelFile = @"MVT\MVTStandard.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            filename = @""+ ART + ".xls";
            sheetName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInARTICLE(dsSource.Tables["ARTICLE"]);
            if (type == "OpenExcel")  
            {
            base.WriteExcelReport(type);
            }
            
            //"OpenExcel";"DirectPrint";"JustExcel";            
            if (type == "DirectPrint")
            {
                
                //MessageBox.Show("你是否打开Exclel?",,MessageBoxButtons.YesNo,MessageBoxDefaultButton.Button2);
                exAgent.PrintOut(type, 1, copies, chooseprinter);
                exAgent.Save();
                exAgent.Close();
            }
           
        }
        public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "ARTICLE";
            strExcelFile = @"MVT\MVTStandard.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filename = @"品种资料" + filedate + ".xls";
            sheetName = DateTime.Now.ToShortTimeString().Replace(@":", "");
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInExcelData(columns, dsSource, 3, 1);
            base.WriteExcelReport("OpenExcel");
        }
        #endregion
    }
}